//
//  LYStatusToolBar.swift
//  微博
//
//  Created by liuerying on 16/5/25

//微博底部工具条

import UIKit

import SnapKit
//定义等宽
private let itemWidth:CGFloat = ScreeWidth / 3
private let barItemMagin:CGFloat = 3
class LYStatusToolBar: UIView {

    var statusViewModel: LYStatusViewModel?{
    
        didSet{
        
            repostBtn.setTitle(statusViewModel?.repostsText, forState: .Normal)
            
            commentBtn.setTitle(statusViewModel?.commentsText, forState: .Normal)
            
            goodBtn.setTitle(statusViewModel?.attitudesText, forState: .Normal)
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
        backgroundColor = UIColor(white: 0.95, alpha: 1)

//        backgroundColor = UIColor.orangeColor()
    }
    
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    
    //设置界面
   private func setupUI(){
   
    //调加按钮
    addChildBtn(repostBtn, title: "转发", imageName: "timeline_icon_retweet")
    addChildBtn(commentBtn, title: "评论", imageName: "timeline_icon_comment")
    addChildBtn(goodBtn, title: "赞", imageName: "timeline_icon_like")

    //转发按钮的约束
    repostBtn.snp_makeConstraints { (make) in
        make.left.top.bottom.equalTo(self)
    
        
        
    }
 
    
    //评论
    commentBtn.snp_makeConstraints { (make) in
        make.top.bottom.equalTo(repostBtn)
        make.left.equalTo(repostBtn.snp_right)
        
        make.width.equalTo(itemWidth)
    }
    
    //点赞的按钮
    goodBtn.snp_makeConstraints { (make) in
        
        make.top.bottom.equalTo(repostBtn)
        make.right.equalTo(self)
        make.left.equalTo(commentBtn.snp_right)
        make.width.equalTo(itemWidth)
    }
    
    //定义分割线
    let sepView1 = linView()
    let sepView2 = linView()
    //根据屏幕子设置宽度
    let width = 1/UIScreen.mainScreen().scale
    
    //添加中间分割线
    addSubview(sepView1)
    addSubview(sepView2)

//    commentBtn.addSubview(sepView1)
//    goodBtn.addSubview(sepView2)
    
    sepView1.snp_makeConstraints { (make) in
        make.left.equalTo(repostBtn.snp_right)
        make.centerY.equalTo(self.snp_centerY)
        //设置黄金分割比
        make.height.equalTo(self.snp_height).multipliedBy(0.4)
        make.width.equalTo(width)
    }
    
    sepView2.snp_makeConstraints { (make) in
        make.left.equalTo(commentBtn.snp_right)
        make.centerY.equalTo(self.snp_centerY)
        //设置黄金分割比
        make.height.equalTo(self.snp_height).multipliedBy(0.4)
        make.width.equalTo(width)
    }
    }
    
    
   private func linView()->UIView{
    
    let line = UIView()
    line.backgroundColor = UIColor.orangeColor()

    return line
    }
    //封装添加按钮 详细信息 的方法
    private func addChildBtn(btn:UIButton,title:String,imageName:String){
    
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
       btn.setTitle(title, forState: .Normal)
        btn.titleLabel?.textAlignment = .Center
        btn.setImage(UIImage(named: imageName), forState: .Normal)
      
        btn.titleLabel?.font = UIFont.systemFontOfSize(13)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
          btn.sizeToFit()//添加到self上
        self.addSubview(btn)
        
        
    }
    
    //转发按钮
    lazy var repostBtn: UIButton = UIButton()
    //评论
    lazy var commentBtn:UIButton = UIButton()
    //赞
    lazy var goodBtn :UIButton = UIButton()
    

    
}


